from django.db import models
from dingxiang.utils.models import BaseModel
# Create your models here.
from django.db import models

# Create your models here.

# 急救方向
class GuideDirection(BaseModel):
    name = models.CharField(max_length=20, null=True, verbose_name='急救方向名称')

    def __str__(self):
        return self.name

    class Meta():
        db_table = 'guide_direction'
        verbose_name_plural = '急救方向'

# 急救分类
class GuideClassification(BaseModel):
    name = models.CharField(max_length=20, null=True, verbose_name='急救分类名称')
    guide_direction = models.ManyToManyField(GuideDirection, null=True, blank=True, related_name="classification_description", verbose_name='急救方向')

    def __str__(self):
        return self.name

    class Meta():
        db_table = 'guide_classification'
        verbose_name_plural = '急救分类'

# 急救名称
class GuideDescription(BaseModel):
    name = models.CharField(max_length=20, null=True, verbose_name='急救名称')
    guide_classification = models.ForeignKey(GuideClassification, null=True, blank=True, on_delete=models.DO_NOTHING, related_name="guide_classification", verbose_name='急救分类')

    def __str__(self):
        return self.name

    class Meta():
        db_table = 'guide_description'
        verbose_name_plural = '急救名称'

# 急救信息
class  GuideContent(BaseModel):
    title = models.CharField(max_length=200, null=True, verbose_name='标题')
    time = models.DateTimeField(auto_now_add=True, null=True, verbose_name='时间')
    author = models.CharField(max_length=100, null=True, verbose_name='作者')
    text = models.TextField(verbose_name='内容')
    references = models.TextField(verbose_name='参考文献', null=True)
    video = models.FileField(upload_to='videos/', verbose_name='视频', blank=True, null=True)
    image = models.ImageField(upload_to='guide/', verbose_name='图片', blank=True, null=True)
    recommend_home = models.BooleanField(default=False,verbose_name='是否推荐首页栏目', null=True)
    guide_description = models.OneToOneField(GuideDescription, on_delete=models.DO_NOTHING, null=True, blank=True, related_name='guide_description', verbose_name='急救名称')

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'guide_content'
        verbose_name_plural = '急救信息'